Skip to content

Astarte Import: Fix astarte import test#1069

Open
osmanhadzic wants to merge 1 commit intoastarte-platform:masterfrom
osmanhadzic:fix/astarte-import-test
Open

Astarte Import: Fix astarte import test#1069
osmanhadzic wants to merge 1 commit intoastarte-platform:masterfrom
osmanhadzic:fix/astarte-import-test

Conversation

@osmanhadzic
Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Sets up an Astarte realm instance pre-populated with data (devices, interfaces, endpoints) to facilitate testing for data imports.
Drops the database after testing to maintain a clean environment.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?
  • Yes
  • No

Additional documentation e.g. usage docs, diagrams, etc.:


Comment on lines +3 to +5
children = [
{Astarte.DataAccess, xandra_options: Astarte.DataAccess.Config.xandra_options!()}
]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use a different Xandra pool just for tests, so that we're not using DataAccess' resource.

Suggested change
children = [
{Astarte.DataAccess, xandra_options: Astarte.DataAccess.Config.xandra_options!()}
]
xandra_options =
Astarte.DataAccess.Config.xandra_options!()
|> Keyword.put(:name, :test_xandra)
children = [
{Xandra.Cluster, xandra_options}
]

This would mean that all calls to Xandra.Cluster functions should use the new pool, see comment above for an example

end)

on_exit(fn ->
Xandra.Cluster.run(:astarte_data_access_xandra, fn conn ->
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Xandra.Cluster.run(:astarte_data_access_xandra, fn conn ->
Xandra.Cluster.run(:test_xandra, fn conn ->

Comment on lines +90 to +94
setup do
Xandra.Cluster.run(:astarte_data_access_xandra, fn conn ->
DatabaseTestHelper.seed_data(conn)
end)
end
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually setup blocks are below setup_alls, as setup_all runs before all tests in a case and setup runs before each test in a case. See https://hexdocs.pm/ex_unit/ExUnit.Callbacks.html#setup_all/2

{Astarte.DataAccess, xandra_options: Astarte.DataAccess.Config.xandra_options!()}
]

Supervisor.start_link(children, strategy: :one_for_one)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider whether this could be changed to a start_supervised call inside a setup_all block (see https://hexdocs.pm/ex_unit/ExUnit.Callbacks.html#start_supervised/2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I tried to implement your suggestion, but in this case, it doesn’t work. I think this PR can resolve my problem with database connections. #1061

Comment on lines +322 to +326
Xandra.execute(conn, @drop_keyspace, [], [])
:timer.sleep(3000)

Xandra.execute(conn, @delete_realm_from_astarte_realms, [], [])
:timer.sleep(3000)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are sleep really needed here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I removed sleep from the code.

@osmanhadzic osmanhadzic changed the title Fix/astarte import test Astarte Import: Fix astarte import test Feb 18, 2025
Implement a database test helper for use in `populatedb_test`.
to test import xml file into the database.
Edit test xml file to be identical like expected xml file in
`astarte_export`.

Add `database_test_helper.exs` to help with setting up the database for
tests.

Signed-off-by: Osman Hadzic <osman.hadzic@secomind.com>
@osmanhadzic osmanhadzic force-pushed the fix/astarte-import-test branch from 4620071 to 6d4a9d7 Compare February 19, 2025 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants